package com.quanta.anag.candidati;

import com.quanta.anag.candidati.ricerca.CandidatiItmesProvider;
import java.util.List;
import com.icesoft.faces.component.ext.HtmlPanelGroup;
import com.icesoft.faces.component.ext.HtmlDataTable;
import com.quanta.anag.candidati.dynamicjsf.JsfDataTable;
import com.quanta.anag.candidati.dynamicjsf.JsfDataTableColumn;
import com.quanta.anag.candidati.dynamicjsf.JsfDateConverter;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author roberto
 */
public class DynamicRisultatiDataTable {

    private final CandidatiItmesProvider candidatiItmesProvider;
    private HtmlPanelGroup htmlPanelGroup;
    private HtmlDataTable prova;

    public DynamicRisultatiDataTable(CandidatiItmesProvider candidatiItmesProvider) {
        this.candidatiItmesProvider = candidatiItmesProvider;
    }

    public void setHtmlPanelGroup(HtmlPanelGroup htmlPanelGroup) {
        this.htmlPanelGroup = htmlPanelGroup;
    }

    public HtmlDataTable getProva() {
        return prova;
    }

    public void setProva(HtmlDataTable prova) {
        this.prova = prova;
    }

    public HtmlPanelGroup getHtmlPanelGroup() {
        if (htmlPanelGroup == null) {
            populate();
        }
        return htmlPanelGroup;

    }

    private void populate() {
        JsfDataTable jsfDataTable = configureDataTable();

        jsfDataTable.addColumn(new JsfDataTableColumn("c-foto-cand c-foto-cand-#{currentRow.candidato.codSesso}", "", "#{currentRow.candidato.codSesso}"));
        jsfDataTable.addColumn(new JsfDataTableColumn("c-dati-top", "#{bundle.Risultati_Codice}", "#{currentRow.candidato.pkCandidato}"));
        jsfDataTable.addColumn(new JsfDataTableColumn("c-dati-top", "#{bundle.Risultati_nome_cog}", "#{currentRow.candidato.nome} #{currentRow.candidato.cognome}"));
        jsfDataTable.addColumn(new JsfDataTableColumn("c-dati-fissi", "#{bundle.Risultati_data_reg}", "#{currentRow.candidato.dataInserimento}", new JsfDateConverter()));
        jsfDataTable.addColumn(new JsfDataTableColumn("c-dati-altri", "#{bundle.Risultati_ultima_professione}", "#{currentRow.candidato.ultimaEsperienza.descrizione}"));
        jsfDataTable.addColumn(new JsfDataTableColumn("c-dati-altri", "#{bundle.Risultati_settore}", "#{currentRow.candidato.ultimaEsperienza.settore}"));

        htmlPanelGroup = new HtmlPanelGroup();
        htmlPanelGroup.getChildren().add(jsfDataTable.createHtmlDataTable());
    }

    private JsfDataTable configureDataTable() {
        JsfDataTable jsfDataTable = new JsfDataTable();
        jsfDataTable.setValue("#{SessionBean.candidati.candidatiItems}", List.class);
        jsfDataTable.setStyleClass("g-risultati");
        jsfDataTable.setHeaderClass("list-header");
        jsfDataTable.setRowClasses("list-row-even,list-row-odd");
        jsfDataTable.setColumnClasses("c-risultati");
        jsfDataTable.setVarName("currentRow");
        jsfDataTable.createHtmlDataTable();
        return jsfDataTable;
    }
}
